package com.hspedu.method;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/2/15
 * @time 16:22
 */
public class ThreadMethod02 {
    public static void main(String[] args) throws InterruptedException {
        int count = 0;
        T1 t1 = new T1();
        t1.start();

        while (true){
            System.out.println("hi" + (++count) + " "+ Thread.currentThread().getName());
            if (count == 5)
                t1.join();
            if (count == 20)
                break;
            Thread.sleep(1000);
        }

    }
}

class T1 extends Thread{

    @Override
    public void run() {
        int count = 0;
        while (true){
            System.out.println("hello " + (++count)+ " "+ Thread.currentThread().getName());

            if (count == 20)
                break;
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
